package com.jzz.eletuanbackend.controller;

import com.jzz.eletuanbackend.service.AuthService;
import com.jzz.eletuanbackend.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthService authService;

    @PostMapping("/sign_in")
    public Msg signIn(@RequestParam("phone") String phone, @RequestParam("password") String password,
                      HttpServletResponse response, HttpServletRequest request) {
        return authService.signIn(request, response, phone, password);
    }

    @PostMapping("/sign_up/customer")
    public Msg signUpAsCustomer(@RequestParam("phone") String phone,
                                @RequestParam("password") String password,
                                @RequestParam(value = "displayName", required = false) String displayName) {
        return authService.signUpAsCustomer(phone, password, displayName);
    }

    @PostMapping("/sign_up/business")
    public Msg signUpAsBusiness(@RequestParam("phone") String phone,
                                @RequestParam("password") String password) {
        return authService.signUpAsBusiness(phone, password);
    }

    @PostMapping("/sign_up/deliverer")
    public Msg signUpAsDeliverer(@RequestParam("phone") String phone,
                                 @RequestParam("password") String password,
                                 @RequestParam("name") String name,
                                 @RequestParam("healthId") String healthId) {
        return authService.signUpAsDeliverer(phone, password, name, healthId);
    }

    @RequestMapping("/valid/{token}")
    public Msg isValidToken(@PathVariable("token") String token) {
        return authService.isValidToken(token);
    }

    @PostMapping("/info/{token}")
    public Msg getUserInformation(@PathVariable("token") String token) {
        return authService.info(token);
    }
}
